package com.ptmall.app.net.http;

import android.util.Log;

import com.google.gson.Gson;
import com.ptmall.app.net.base.Result;

import java.io.IOException;
import java.lang.reflect.Type;

import okhttp3.ResponseBody;
import retrofit2.Converter;

/**
 * Created by Charles on 2016/3/17.
 */
class GsonResponseBodyConverter<T> implements Converter<ResponseBody, T> {
    private final Gson gson;
    private final Type type;

    GsonResponseBodyConverter(Gson gson, Type type) {
        this.gson = gson;
        this.type = type;
    }

    @Override
    public T convert(ResponseBody value) throws IOException {
        String response = value.string();
            Log.d("Network", "response>>" + response);
            //result 只解析result字段
            Result result = gson.fromJson(response, Result.class);
            if (result != null) {
                Log.d("xucc", result.toString());
            } else {
                Log.d("xucc","result == null");
            }
            return gson.fromJson(response, type);


    }
}
